﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

namespace RN.ERP.Web.Person
{
    public partial class ImportEmpCertTest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {   string str=string.Empty;
            if (txtCard.Text.Trim().Length > 0)
            {
                str = InnerImportEmpTitleDetails(txtCard.Text.Trim());
            }
            if (string.IsNullOrEmpty(str) || str.Length <= 0)
            {
                lblMessage.Text = "注册中心没有证书返回";
            }
            else
            {
                lblMessage.Text = str;
            }

        }

        /// <summary>
        /// 从注册中心取用户的执业注册信息。
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns></returns>
        private string InnerImportEmpTitleDetails(string idCard)
        {
            try
            {
                string importUrl = "http://shenbao.ljzc.net/ZhaoBiao/GetZCRY_Info?username=ljzcZB&pwd=ljzcZB&idcard=";
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(importUrl + idCard);
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                Stream newStream = myRequest.GetRequestStream();
                newStream.Close();
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                StreamReader reader = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                return reader.ReadToEnd();
            }
            catch { }
            return null;
        }
    }
}